﻿using System;
using NUnit.Framework;

namespace RenewalProjects.Libraries.Reflection.Tests
{
    [TestFixture]
    public class LambdaTemplateFixture
    {
        [Test]
        public void Valid_template_method_supplied_returns_valid_typed_method()
        {
            var template = new LambdaTemplate<string, int>(SampleTemplate);
            var lambdaResult = template.GetLambdaFor<string>();
            var actual = lambdaResult("stuff");
            var expected = "stuff".GetHashCode();
            Assert.AreEqual(expected, actual);
        }

        [ExpectedException(typeof(ArgumentException))]
        [Test]
        public void Specifying_lambda_will_not_work()
        {
            new LambdaTemplate<string, int>((i) => i.GetHashCode());
        }

        private int SampleTemplate<TInput>(TInput input)
        {
            return input.GetHashCode();
        }
    }
}